package site.brood.log.controller;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.brood.common.core.time.TimeUtil;
import site.brood.common.core.web.AjaxJson;
import site.brood.common.log.pojo.LogLoginDto;
import site.brood.common.security.annotation.InnerAuth;
import site.brood.log.entity.LogLogin;
import site.brood.log.service.LogLoginService;

/**
 * 操作日志记录
 */
@RestController
@RequestMapping("/loginlog")
public class LoginLogController {

    @Autowired
    private LogLoginService loginLogService;

    @InnerAuth
    @PostMapping("/add")
    public AjaxJson add(@RequestBody LogLoginDto loginLog)
    {
        if(null == loginLog.getAccessTime())
            loginLog.setAccessTime(TimeUtil.getNowDate());
        LogLogin logLogin = new LogLogin();
        BeanUtils.copyProperties(loginLog, logLogin);
        boolean isSaved = loginLogService.saveOrUpdate(logLogin);
        return AjaxJson.success(isSaved);
    }
}

